WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
wolf.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Enable project-specific definitions and macros
22#include "core/internal/config.h"
24#include "core/utils/logging.h"
26
27// Folder Registry
29
30// includes from Eigen lib
31#include <Eigen/Dense>
32#include <Eigen/Geometry>
33#include <Eigen/Sparse>
34
35#include <libgen.h>
36
37// includes from std lib
38#include <list>
39#include <map>
40#include <memory> // shared_ptr and weak_ptr
41#include <set>
42
43// System specifics
44#include <sys/stat.h>
45
46// YAML
47#include "yaml-cpp/yaml.h"
48#include "yaml-schema-cpp/yaml_conversion.hpp"
49
50namespace wolf
51{
58typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE SizeEigen;
59
66typedef std::size_t SizeStd;
67
68#define M_TORAD 0.017453292519943295769236907684886127134 // pi / 180
69#define M_TODEG 57.295779513082320876798154814105170332 // 180 / pi
70
71namespace Constants
72{
73// Wolf standard tolerance
74const double EPS = 1e-8;
75// Wolf smmmmall tolerance
76const double EPS_SMALL = 1e-16;
77} // namespace Constants
78
79} // namespace wolf
80
82// Construct types for any scalar defined in the typedef double above
84
90namespace Eigen // Eigen namespace extension
91{
92// 1. Vectors and Matrices
93typedef Matrix<double, 1, 1> Matrix1d;
94typedef Matrix<double, 5, 5> Matrix5d;
95typedef Matrix<double, 6, 6> Matrix6d;
96typedef Matrix<double, 7, 7> Matrix7d;
97typedef Matrix<double, 8, 8> Matrix8d;
98typedef Matrix<double, 9, 9> Matrix9d;
99typedef Matrix<double, 10, 10> Matrix10d;
100typedef Matrix<double, 1, 1> Vector1d;
101typedef Matrix<double, 5, 1> Vector5d;
102typedef Matrix<double, 6, 1> Vector6d;
103typedef Matrix<double, 7, 1> Vector7d;
104typedef Matrix<double, 8, 1> Vector8d;
105typedef Matrix<double, 9, 1> Vector9d;
106typedef Matrix<double, 10, 1> Vector10d;
107
108// 2. Sparse matrix
109typedef SparseMatrix<double> SparseMatrixd;
110
111// 3. Row major matrix
112typedef Matrix<double, Dynamic, Dynamic, RowMajor> MatrixRowXd;
113} // namespace Eigen
114
115namespace wolf
116{
118/* Check Eigen Matrix sizes, both statically and dynamically
119 *
120 * Help:
121 *
122 * The WOLF project implements many template functions using Eigen Matrix and Quaterniond, in different versions
123 * (Static size, Dynamic size, Map, Matrix expression).
124 *
125 * Eigen provides some macros for STATIC assert of matrix sizes, the most common of them are (see Eigen's
126 * StaticAssert.h):
127 *
128 * EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE
129 * EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE
130 * EIGEN_STATIC_ASSERT_VECTOR_ONLY
131 *
132 * but they do not work if the evaluated types are of dynamic size.
133 *
134 * In order to achieve full templatization over both dynamic and static sizes, we use extensively a prototype of this
135 * kind:
136 *
137 * template<typename Derived>
138 * inline Eigen::Matrix<typename Derived::Scalar, 3, 3> function(const Eigen::MatrixBase<Derived>& _v){
139 *
140 * MatrixSizeCheck<3,1>::check(_v); /// We check here the size of the input parameter
141 *
142 * typedef typename Derived::Scalar T;
143 *
144 * ... code ...
145 *
146 * return M;
147 * }
148 *
149 * The function : MatrixSizeCheck <Rows, Cols>::check(M) checks that the Matrix M is of size ( Rows x Cols ).
150 * This check is performed statically or dynamically, depending on the type of argument provided.
151 */
154template <int Size, int DesiredSize>
156{
159 template <typename T>
161 {
162 static_assert(Size == DesiredSize, "Size of static Vector or Matrix does not match");
163 }
164};
165//
168template <int DesiredSize>
169struct StaticSizeCheck<Eigen::Dynamic, DesiredSize>
170{
173 template <typename T>
174 StaticSizeCheck(const T& t)
175 {
176 assert(t == DesiredSize && "Size of dynamic Vector or Matrix does not match");
177 }
178};
179//
182template <int DesiredR, int DesiredC>
184{
193 template <typename T>
194 static void check(const T& t)
195 {
198 }
199};
200
201//
202// End of check matrix sizes /////////////////////////////////////////////////
203
205// TYPEDEFS FOR POINTERS, LISTS AND ITERATORS IN THE WOLF TREE
207
208#define WOLF_DECLARED_PTR_TYPEDEFS(Name) \
209 typedef std::shared_ptr<Name> Name##Ptr; \
210 typedef std::shared_ptr<const Name> Name##ConstPtr; \
211 typedef std::weak_ptr<Name> Name##WPtr; \
212 typedef std::weak_ptr<const Name> Name##ConstWPtr;
213
214#define WOLF_DECLARED_LIST_TYPEDEFS(Name) \
215 typedef std::list<Name##Ptr> Name##PtrList; \
216 typedef Name##PtrList::iterator Name##PtrListIter; \
217 typedef Name##PtrList::const_iterator Name##PtrListConstIter; \
218 typedef Name##PtrList::reverse_iterator Name##PtrListRevIter; \
219 typedef std::list<Name##WPtr> Name##WPtrList; \
220 typedef Name##WPtrList::iterator Name##WPtrListIter; \
221 typedef Name##WPtrList::const_iterator Name##WPtrListConstIter; \
222 typedef Name##WPtrList::reverse_iterator Name##WPtrListRevIter; \
223 typedef std::list<Name##ConstPtr> Name##ConstPtrList; \
224 typedef Name##ConstPtrList::iterator Name##ConstPtrListIter; \
225 typedef Name##ConstPtrList::const_iterator Name##ConstPtrListConstIter; \
226 typedef Name##ConstPtrList::reverse_iterator Name##ConstPtrListRevIter; \
227 typedef std::list<Name##ConstWPtr> Name##ConstWPtrList; \
228 typedef Name##ConstWPtrList::iterator Name##ConstWPtrListIter; \
229 typedef Name##ConstWPtrList::const_iterator Name##ConstWPtrListConstIter; \
230 typedef Name##ConstWPtrList::reverse_iterator Name##ConstWPtrListRevIter;
231
232#define WOLF_DECLARED_SET_TYPEDEFS(Name) \
233 typedef std::set<Name##Ptr> Name##PtrSet; \
234 typedef Name##PtrSet::iterator Name##PtrSetIter; \
235 typedef Name##PtrSet::const_iterator Name##PtrSetConstIter; \
236 typedef Name##PtrSet::reverse_iterator Name##PtrSetRevIter; \
237 typedef std::set<Name##WPtr> Name##WPtrSet; \
238 typedef Name##WPtrSet::iterator Name##WPtrSetIter; \
239 typedef Name##WPtrSet::const_iterator Name##WPtrSetConstIter; \
240 typedef Name##WPtrSet::reverse_iterator Name##WPtrSetRevIter; \
241 typedef std::set<Name##ConstPtr> Name##ConstPtrSet; \
242 typedef Name##ConstPtrSet::iterator Name##ConstPtrSetIter; \
243 typedef Name##ConstPtrSet::const_iterator Name##ConstPtrSetConstIter; \
244 typedef Name##ConstPtrSet::reverse_iterator Name##ConstPtrSetRevIter; \
245 typedef std::set<Name##ConstWPtr> Name##ConstWPtrSet; \
246 typedef Name##ConstWPtrSet::iterator Name##ConstWPtrSetIter; \
247 typedef Name##ConstWPtrSet::const_iterator Name##ConstWPtrSetConstIter; \
248 typedef Name##ConstWPtrSet::reverse_iterator Name##ConstWPtrSetRevIter;
249
250#define WOLF_PTR_TYPEDEFS(ClassName) \
251 class ClassName; \
252 WOLF_DECLARED_PTR_TYPEDEFS(ClassName); \
253 WOLF_DECLARED_LIST_TYPEDEFS(ClassName); \
254 WOLF_DECLARED_SET_TYPEDEFS(ClassName);
255
256#define WOLF_STRUCT_PTR_TYPEDEFS(StructName) \
257 struct StructName; \
258 WOLF_DECLARED_PTR_TYPEDEFS(StructName); \
259 WOLF_DECLARED_LIST_TYPEDEFS(StructName); \
260 WOLF_DECLARED_SET_TYPEDEFS(StructName);
261
262// NodeBase
264
265// NodeStateBlocks
267
268// Problem
270
271// Tree Manager
273
274// Hardware
276
277// - Sensors
279
280// - Processors
282
283// - ProcessorMotion
285
286// Trajectory
288
289// - Frame
291
292class TimeStamp;
293typedef std::map<TimeStamp, FrameBasePtr> FramePtrMap;
294typedef std::map<TimeStamp, FrameBaseConstPtr> FrameConstPtrMap;
295
296// - Capture
298
299// - Feature
301
302// - Factor
304
305// Map
307
308// - Landmark
310
311// - - State blocks
317
318// - - Local Parametrization
320
321// ==================================================
322// Some dangling functions
323
326inline bool file_exists(const std::string& _name)
327{
328 struct stat buffer;
329 return (stat(_name.c_str(), &buffer) == 0);
330}
331
334inline const Eigen::Vector3d gravity(void)
335{
336 return Eigen::Vector3d(0, 0, -9.806);
337}
338
339// ===================================================
340// Schema folder registry
341WOLF_REGISTER_FOLDER("core", _WOLF_SCHEMA_DIR);
342
343} // namespace wolf
Base class of captures: a sensor measurement taken at a time stamp, linked to a frame,...
Definition: capture_base.h:41
Base class of factors: a constraint between state blocks of one or more nodes, given a measurement an...
Definition: factor_base.h:73
Base class of features: a measurement with its uncertainty, extracted from a capture,...
Definition: feature_base.h:40
Base class of frames: the states of the robot at a time stamp, in the trajectory, with the captures t...
Definition: frame_base.h:40
Hardware: the sensors of the problem.
Definition: hardware_base.h:37
Base class of landmarks: elements of the map with state blocks, observed from the frames.
Definition: landmark_base.h:93
Base class of local parametrizations: plus and minus operations of a state with increments in its tan...
Definition: local_parametrization_base.h:29
Base class of maps: container of the landmarks.
Definition: map_base.h:99
Base class for Nodes.
Definition: node_base.h:73
Base class of the nodes having state blocks (sensors, frames, captures and landmarks)
Definition: node_state_blocks.h:36
Wolf problem: root of the wolf tree (hardware, trajectory and map). It manages the motion providers,...
Definition: problem.h:66
Base class of processors: they process the captures of a sensor and the keyframes created by other pr...
Definition: processor_base.h:120
Base class of motion processors: they integrate motion data into the robot state.
Definition: processor_motion.h:110
Base class of sensors: their state blocks (extrinsics and intrinsics, static or dynamic),...
Definition: sensor_base.h:128
State block of an angle (2D orientation), wrapped to [-pi, pi].
Definition: state_angle.h:29
State block: a state vector of a variable of the nonlinear optimization.
Definition: state_block.h:73
State block for general 2D points and positions.
Definition: state_block_derived.h:92
State block for general 3D points and positions.
Definition: state_block_derived.h:162
State block of a unit quaternion (3D orientation), stored as (x, y, z, w)
Definition: state_quaternion.h:29
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
Trajectory: the frames of the problem, ordered by time stamp.
Definition: trajectory_base.h:39
Base class of tree managers: they manage the wolf tree (e.g. removing or fixing frames) at each new k...
Definition: tree_manager_base.h:75
Namespace extending Eigen definitions.
Definition: wolf.h:91
Matrix< double, 6, 6 > Matrix6d
6x6 matrix of real double type
Definition: wolf.h:95
Matrix< double, Dynamic, Dynamic, RowMajor > MatrixRowXd
Dynamic row-major matrix of real double type.
Definition: wolf.h:112
Matrix< double, 5, 5 > Matrix5d
5x5 matrix of real double type
Definition: wolf.h:94
Matrix< double, 7, 7 > Matrix7d
7x7 matrix of real double type
Definition: wolf.h:96
Matrix< double, 10, 10 > Matrix10d
10x10 matrix of real double type
Definition: wolf.h:99
Matrix< double, 10, 1 > Vector10d
10-vector of real double type
Definition: wolf.h:106
Matrix< double, 1, 1 > Vector1d
1-vector of real double type
Definition: wolf.h:100
Matrix< double, 1, 1 > Matrix1d
1x1 matrix of real double type
Definition: wolf.h:93
Matrix< double, 7, 1 > Vector7d
7-vector of real double type
Definition: wolf.h:103
Matrix< double, 5, 1 > Vector5d
5-vector of real double type
Definition: wolf.h:101
Matrix< double, 8, 8 > Matrix8d
8x8 matrix of real double type
Definition: wolf.h:97
Matrix< double, 6, 1 > Vector6d
6-vector of real double type
Definition: wolf.h:102
Matrix< double, 9, 1 > Vector9d
9-vector of real double type
Definition: wolf.h:105
SparseMatrix< double > SparseMatrixd
Sparse matrix of real double type.
Definition: wolf.h:109
Matrix< double, 9, 9 > Matrix9d
9x9 matrix of real double type
Definition: wolf.h:98
Matrix< double, 8, 1 > Vector8d
8-vector of real double type
Definition: wolf.h:104
const double EPS_SMALL
Definition: wolf.h:76
const double EPS
Definition: wolf.h:74
Definition: capture_base.h:23
std::size_t SizeStd
Other containers size type for the Wolf project.
Definition: wolf.h:66
std::map< TimeStamp, FrameBaseConstPtr > FrameConstPtrMap
Definition: wolf.h:294
std::map< TimeStamp, FrameBasePtr > FramePtrMap
Definition: wolf.h:293
EIGEN_DEFAULT_DENSE_INDEX_TYPE SizeEigen
Vector and Matrices size type for the Wolf project.
Definition: wolf.h:58
bool file_exists(const std::string &_name)
Returns whether a file exists.
Definition: wolf.h:326
WOLF_REGISTER_FOLDER("core", _WOLF_SCHEMA_DIR)
const Eigen::Vector3d gravity(void)
Returns the gravity vector [0, 0, -9.806] (m/s²)
Definition: wolf.h:334
WOLF_PTR_TYPEDEFS(CaptureLandmarksExternal)
Checks the size of an Eigen matrix: statically if fixed-size, at run time if dynamic.
Definition: wolf.h:184
static void check(const T &t)
Asserts the matrix size dynamically or statically.
Definition: wolf.h:194
StaticSizeCheck(const T &t)
Asserts at run time that the size is the desired one.
Definition: wolf.h:174
Static assertion of the size of a fixed-size Eigen matrix (see MatrixSizeCheck)
Definition: wolf.h:156
StaticSizeCheck(const T &)
Asserts statically that the size is the desired one.
Definition: wolf.h:160